Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sidecars of annotated namespaces when annotation is deleted #1209

Merged
merged 2 commits into from
Sep 24, 2020

Conversation

rubenvp8510
Copy link
Collaborator

@rubenvp8510 rubenvp8510 commented Sep 22, 2020

Fixes #906

Signed-off-by: Ruben Vargas [email protected]

@codecov
Copy link

codecov bot commented Sep 22, 2020

Codecov Report

Merging #1209 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1209   +/-   ##
=======================================
  Coverage   87.32%   87.32%           
=======================================
  Files          89       89           
  Lines        4891     4891           
=======================================
  Hits         4271     4271           
  Misses        457      457           
  Partials      163      163           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6978846...9b80ba7. Read the comment docs.

@jpkrohling jpkrohling changed the title Delete injected sidecars of annotated namespaces when annotation is d… Remove sidecars of annotated namespaces when annotation is deleted Sep 23, 2020
// If deployment don't have the annotation and has an agent, this may be injected by the namespace
// we need to clean it.
agent, _ := inject.HasJaegerAgent(dep)
_, depAnnotation := dep.Annotations[inject.Annotation]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/depAnnotation/ok -- you are not getting the annotation, you are getting a boolean on whether it was found.

agent, _ := inject.HasJaegerAgent(dep)
_, depAnnotation := dep.Annotations[inject.Annotation]
if agent && !depAnnotation{
jaegerInstance, label := dep.Labels[inject.Label]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

"jaeger": jaegerInstance,
}).Info("Removing Jaeger Agent sidecar")
inject.CleanSidecar(jaegerInstance, dep)
if err := r.client.Update(ctx, dep); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Patch instead of Update, to reduce the risk of failure. Look at this one for reference: open-telemetry/opentelemetry-operator#54

log.WithFields(log.Fields{
"deployment": dep.Name,
"namespace": dep.Namespace,
"jaeger": jaegerInstance,
}).Info("Removing Jaeger Agent sidecar")
patch := client.MergeFrom(dep.DeepCopy())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If dep is a pointer, you might not need to do a DeepCopy, you can just dereference it.

Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A minor comment on the dep.DeepCopy(), but this looks good. Have you done manual testing of this?

@rubenvp8510
Copy link
Collaborator Author

Yes I did manual testing, with the steps detailed in the issue on how to reproduce.

@jpkrohling jpkrohling merged commit c239477 into jaegertracing:master Sep 24, 2020
chgl pushed a commit to chgl/jaeger-operator that referenced this pull request Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent sidecars are not cleared when annotation is deleted from namespace
2 participants